package com.services.impl;

import com.dao.IFlightDao;
import com.dao.IOrderDao;
import com.dao.impl.FlightDaoImpl;
import com.dao.impl.OrderDaoImpl;
import com.model.ForderModel;
import com.model.PageBeanMode;
import com.services.IOrderServices;

import java.util.List;
import java.util.Map;

/**
 * @Program: exam
 * @ClassName: OrderServicesImpl
 * @Description:
 * @Author: li
 * @Create: 2019-07-24 16:19
 */
public class OrderServicesImpl implements IOrderServices {
    IOrderDao dao = new OrderDaoImpl();
    IFlightDao cdao = new FlightDaoImpl();

    @Override
    public void addOrder(ForderModel forderModel) {
        //将航班状态改为租用 0
        cdao.changeFlightStatus(forderModel.getFid(),0);
        //将记录添加到数据库中
        dao.addOrder(forderModel);
    }

    @Override
    public List<ForderModel> queryOrderByEmail(String email, int status) {
        return dao.queryOrderByEmail(email,status);
    }

    @Override
    public void successOrder(ForderModel forderModel) {
        //将航班状态改为上架 1
        cdao.changeFlightStatus(forderModel.getFid(),1);
        //更新订单状态，改为-1 订单已完成，已退款
        dao.reFlight(forderModel.getOid());
    }

    @Override
    public PageBeanMode<ForderModel> pageOrder(String _pageStart, String _pageSize, Map<String, String[]> map) {
        int pageStart = Integer.parseInt(_pageStart);
        int pageSize = Integer.parseInt(_pageSize);

        List<ForderModel> forderModels = dao.pageOrder((pageStart - 1) * pageSize, pageSize, map);
        int totalData = dao.totalData(map);
        return new PageBeanMode<ForderModel>(pageStart, pageSize, totalData, forderModels);
    }

    @Override
    public void refund(ForderModel forderModel) {
        //将航班状态改2
        dao.reFund(forderModel.getOid());
    }


}
